# @Time    : 2020-01-03 16:06
# @Author  : peng
# @File    : mvn.py maven编译
import logging
from pathlib import Path

from core import sword

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)


def compile_dependencies(gitroot):  # 编译MAVEN依赖
    maven_compile_args = ['clean', 'compile', 'install', '-Dmaven.test.skip=true']
    _compile_maven(gitroot, maven_compile_args)
    # sword.writefile(build_file, '{0} {1}'.format(git_last_hash, git_last_branch))  # 写回版本号


def _compile_maven(cwd, maven_args):
    args = ['mvn', ] + maven_args
    logging.info('[MAVEN] build {0} => {1}'.format(cwd, ' '.join(args)))
    ret = sword.execute_cmd(args, cwd=cwd, timeout=300, pip=False)
    logging.info(ret)
    return ret
    # self._write_sep()
